/*
 * @Author: GaoTang
 * @Company: ShineSoft
 * @Date: 2021-07-23 21:35:15
 * @LastEditors: GaoTang
 * @LastEditTime: 2021-07-25 14:00:43
 * @FilePath: \tpl-shopping\ShoppingClient\common\filter\filter.js
 * @Email: qq23745038@126.com
 */
import Vue from 'vue'
import {
  date
} from '@/common/js/util'


Vue.filter('date', (timeStamp, format = 'Y-m-d H:i') => {
  if (!timeStamp) return '';
  return date(format, timeStamp);
})

Vue.filter('friendDate', (timeStamp, format = 'Y-m-d H:i') => {
  if (!timeStamp) return '';
  return date(format, timeStamp);
})

Vue.filter('price', (price, fixed = 0) => {
  if (!price || isNaN(price)) {
    return 0
  }
  return fixed > 0 ? parseFloat(price).toFixed(fixed) : + parseFloat(price).toFixed(2);
})

Vue.filter('alibaba', (val) => {
  return `https://tplshopping.oss-cn-shanghai.aliyuncs.com/${val}`
})

Vue.filter('html', (val) => {
  if (val) {
    const newVal = val.replace(/<[^>]+>/gi, '')
    if (newVal) {
      return newVal.replace(/&nbsp;/gi, '')
    }
  }
  return ''
})